import config
from woocommerce import API

class WooCommerce:
    def __init__(self):
        self.api = API(
            config.read('wc_url'), 
            config.read('wc_key'),
            config.read('wc_secret'),
            timeout=60
        )

    def batch_goods(self, data):
        response = self.api.post(f"products/batch", {
            "update": data
        })
        if response.status_code == 200:
            return True

    def get_goods(self, sku):
        response = self.api.get(f"products", params={"sku": sku})
        if response.status_code == 200:
            list = response.json()
            if len(list) > 0:
                return list[0]